package com.jungle.mvvm.sample.ui.chat;

import android.databinding.ObservableField;
import android.support.annotation.NonNull;

import com.jungle.mvvm.base.ItemViewModel;
import com.jungle.mvvm.binding.command.BindingAction;
import com.jungle.mvvm.binding.command.BindingCommand;
import com.jungle.mvvm.sample.bean.ArticleBean;
import com.jungle.mvvm.sample.util.ArticleUtil;

/**
 * @ClassName ChatItemViewModel
 * @Description ChatItemViewModel
 * @Author Daniel
 * @Version V1.0.0
 */
public class ChatItemViewModel extends ItemViewModel<ChatKindViewModel> {
    private ArticleBean mArticleBean;
    public ObservableField<Boolean> hasCollect = new ObservableField<>(false);

    public ChatItemViewModel(@NonNull ChatKindViewModel viewModel, ArticleBean articleBean) {
        super(viewModel);
        this.mArticleBean = articleBean;
        hasCollect.set(articleBean.getCollect());
    }

    public ArticleBean getArticleBean() {
        return mArticleBean;
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            ArticleUtil.toDetail(mArticleBean.getTitle(), mArticleBean.getLink(), viewModel);
        }
    });

    public BindingCommand collectClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            ArticleUtil.toCollect(mArticleBean, hasCollect, viewModel);
        }
    });

}
